'Copyright (c) 2008, Jonathan Allen

Public Class InstantQueue
    Inherits Queue

    Public Sub New(ByVal user As User)
        MyBase.New(user)
    End Sub

    Public Overrides Sub Refresh()
        Dim request = NetflixUrls.GetUsersQueuesInstant(User, Nothing, 0, NetflixConstants.MaxInstantQueueItems, Nothing)
        Dim xml = User.Connection.RequestResource(request, User)
        Dim root = XElement.Parse(xml)

        ETag = root.<etag>.Value

        ItemsCore.Clear()
        For Each node In root.<queue_item>
            ItemsCore.Add(New QueueItem(User.Connection, node))
        Next

    End Sub

    Public Overloads Overrides Sub Add(ByVal id As String, ByVal position As Integer?)
        If LastRefresh Is Nothing Then Refresh()

        Dim request = NetflixUrls.PostUsersQueuesInstant(User, id, Nothing, position, ETag)
        Dim xml = User.Connection.RequestResource(request, User)

        'Console.WriteLine(xml)

        'TODO - Learn to parse the result so we don't have to refresh
        Refresh()
    End Sub

End Class
